/*
 * Created by JFormDesigner on Mon Jun 27 13:19:54 CST 2022
 */

package com.keshe.jsp;

import com.keshe.service.RoomInContorller;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.GroupLayout;

/**
 * @author 1
 */
public class ADDRoomIn extends JFrame {
    public ADDRoomIn() {
        initComponents();
    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");
        label1 = new JLabel();
        label2 = new JLabel();
        textField1 = new JTextField();
        label3 = new JLabel();
        textField2 = new JTextField();
        label4 = new JLabel();
        textField3 = new JTextField();
        label5 = new JLabel();
        comboBox1 = new JComboBox<>();
        button1 = new JButton();
        button2 = new JButton();
        label6 = new JLabel();
        textField4 = new JTextField();
        action1 = new back();
        action2 = new addRoomin();

        //======== this ========
        setResizable(false);
        setTitle("\u5165\u4f4f\u529e\u7406");
        setIconImage(new ImageIcon(getClass().getResource("/images/\u9152\u5e97 (1).png")).getImage());
        Container contentPane = getContentPane();

        //---- label1 ----
        label1.setText(bundle.getString("label1.text_14"));
        label1.setHorizontalAlignment(SwingConstants.CENTER);
        label1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 30));
        label1.setIcon(new ImageIcon(getClass().getResource("/images/\u9884\u5148\u767b\u8bb0\u529e\u7406\u5165\u4f4f.png")));

        //---- label2 ----
        label2.setText(bundle.getString("label2.text_8"));
        label2.setIcon(new ImageIcon(getClass().getResource("/images/\u7f16\u53f7.png")));

        //---- label3 ----
        label3.setText(bundle.getString("label3.text_5"));
        label3.setIcon(new ImageIcon(getClass().getResource("/images/\u7528\u6237.png")));

        //---- label4 ----
        label4.setText(bundle.getString("label4.text_2"));
        label4.setIcon(new ImageIcon(getClass().getResource("/images/257\u7528\u6237\u8d44\u6599-\u7ebf\u6027.png")));

        //---- label5 ----
        label5.setText(bundle.getString("label5.text"));
        label5.setIcon(new ImageIcon(getClass().getResource("/images/\u4f4f\u9662\u5929\u6570.png")));

        //---- comboBox1 ----
        comboBox1.setModel(new DefaultComboBoxModel<>(new String[] {
            "1",
            "2",
            "3",
            "4",
            "5"
        }));

        //---- button1 ----
        button1.setAction(action2);

        //---- button2 ----
        button2.setAction(action1);

        //---- label6 ----
        label6.setText("交付押金");
        label6.setIcon(new ImageIcon(getClass().getResource("/images/\u62bc\u91d1.png")));

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                        .addGroup(GroupLayout.Alignment.LEADING, contentPaneLayout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(label1, GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE))
                        .addGroup(GroupLayout.Alignment.LEADING, contentPaneLayout.createSequentialGroup()
                            .addGap(135, 135, 135)
                            .addGroup(contentPaneLayout.createParallelGroup()
                                .addGroup(contentPaneLayout.createSequentialGroup()
                                    .addGroup(contentPaneLayout.createParallelGroup()
                                        .addComponent(label2)
                                        .addComponent(label3)
                                        .addComponent(label4)
                                        .addComponent(label5)
                                        .addComponent(button1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGap(34, 34, 34))
                                .addGroup(contentPaneLayout.createSequentialGroup()
                                    .addComponent(label6)
                                    .addGap(90, 90, 90)))
                            .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                .addComponent(textField1, GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
                                .addComponent(textField2, GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
                                .addComponent(textField3, GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
                                .addComponent(comboBox1, GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
                                .addComponent(button2, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 104, GroupLayout.PREFERRED_SIZE)
                                .addComponent(textField4, GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE))
                            .addGap(0, 108, Short.MAX_VALUE)))
                    .addContainerGap())
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(label1, GroupLayout.PREFERRED_SIZE, 122, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label2)
                        .addComponent(textField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label3)
                        .addComponent(textField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label4)
                        .addComponent(textField3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label5)
                        .addComponent(comboBox1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addGap(9, 9, 9)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label6)
                        .addComponent(textField4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(button2)
                        .addComponent(button1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addContainerGap(32, Short.MAX_VALUE))
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JLabel label2;
    private JTextField textField1;
    private JLabel label3;
    private JTextField textField2;
    private JLabel label4;
    private JTextField textField3;
    private JLabel label5;
    private JComboBox<String> comboBox1;
    private JButton button1;
    private JButton button2;
    private JLabel label6;
    private JTextField textField4;
    private back action1;
    private addRoomin action2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables

    private class back extends AbstractAction {
        private back() {
            // JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
            ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");

            putValue(NAME, bundle.getString("action1.Name_17"));
            // JFormDesigner - End of action initialization  //GEN-END:initComponents
        }

        public void actionPerformed(ActionEvent e) {
            // TODO add your code here
            new RoomInSet().setVisible(true);
            dispose();
        }
    }

    private class addRoomin extends AbstractAction {
        private addRoomin() {
            // JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
            ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");

            putValue(NAME, bundle.getString("action2.Name_11"));
            // JFormDesigner - End of action initialization  //GEN-END:initComponents
        }

        public void actionPerformed(ActionEvent e) {
            // TODO add your code here
            RoomInContorller ri=new RoomInContorller();
            int flag=ri.insertRoomIn(textField1.getText(),textField2.getText(),textField3.getText(),Integer.parseInt(String.valueOf(comboBox1.getSelectedItem())),Integer.parseInt(textField4.getText()));
            switch(flag){
                case -2: {
                    JOptionPane.showMessageDialog(null,"该客房已被占用！");
                    break;
                }
                case -1: {
                    JOptionPane.showMessageDialog(null,"完善信息再提交！");
                    break;
                }
                case 0: {
                    JOptionPane.showMessageDialog(null,"系统中无该客房");
                    break;
                }
                default: {
                    JOptionPane.showMessageDialog(null,"办理成功！");
                    dispose();
                    new RoomInSet().setVisible(true);
                    break;
                }
            }
        }
    }
}
